package kosta.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import kosta.model.CategoryService;
import kosta.model.ProductVO;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CategoryController {
	@Resource(name="categoryServiceImpl")
	private CategoryService categoryService;
	
	//index.jsp에서 forward 로 첫번째 카테고리를 가져오는 메서드 포함
	@RequestMapping("/selectAllFirstCategory.do")
	public ModelAndView selectAllFirstCategory() throws Exception{		
		//맵을 가지고 있는 리스트를 jsp 로 보냄
		List<Map> list=categoryService.selectAllFirstCategory();
		return new ModelAndView("category_list_jquery","firstCategory",	list);
	} 
	
	//근데 '/' 까지 포함시킨 이유가 뭐야?
	@RequestMapping("/selectSecondCategoryByFId.do")
	@ResponseBody//리퀘스트 할 필요없이 매개변수에서 바로 name 으로 요청한걸 받을 수 있나봄
	public List<Map> selectSecondCategoryByFId(String firstCategoryId) throws Exception{		
		List<Map> list=categoryService.selectSecondCategoryByFId(firstCategoryId);
		//System.out.println(firstCategoryId+"--"+list);
		return list;
	}
	
	@RequestMapping("/selectThirdCategoryBySId.do")
	@ResponseBody
	public List<Map> selectThirdCategoryBySId(String secondCategoryId) throws Exception{		
		List<Map> list=categoryService.selectThirdCategoryBySId(secondCategoryId);
		System.out.println(secondCategoryId+"--"+list);
		return list;
	}
	
	//세번째 카테고리로 정보검색
	@RequestMapping("/selectProductInfoByTId.do")
	@ResponseBody
	public List<ProductVO> selectProductInfoByTId(String thirdCategoryId) throws Exception{		
		List<ProductVO> list=categoryService.selectProductInfoByTId(thirdCategoryId);
		System.out.println(thirdCategoryId+"-..-"+list);
		return list;
	}
	
	
	@RequestMapping("/selectProductById.do")
	@ResponseBody
	public Map selectProductById(String productId) throws Exception{		
		ProductVO pvo=categoryService.selectProductById(productId);
		System.out.println(pvo);
		Map map=new HashMap();
		map.put("info", pvo.getProductInfo());
		return map;
	}
}
